<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('答案列表')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="data-form">
                <div class="select-list">
                    <ul>
                        <li hidden="true">
                            <input type="text" name="questionId" hidden="true" th:value="${questionId}"/>
                        </li>
                        <li>
                            审核状态：<select name="auditStatus"
                                         th:with="dicts=${@sysDictDataServiceImpl.listDictDataByTypeSign('tiku_question_audit_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${dicts}" th:text="${dict.dataKey}"
                                    th:value="${dict.dataValue}"></option>
                        </select>
                        </li>
                        <li>
                            使用状态：<select name="use"
                                         th:with="dicts=${@sysDictDataServiceImpl.listDictDataByTypeSign('sys_use_status')}">
                            <option value="">所有</option>
                            <option th:each="dict : ${dicts}" th:text="${dict.dataKey}"
                                    th:value="${dict.dataValue}"></option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="add()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.editFull()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-remove"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    const sys_use_status = [[${@sysDictDataServiceImpl.listDictDataByTypeSign('sys_use_status')}]];
    const tiku_question_audit_status = [[${@sysDictDataServiceImpl.listDictDataByTypeSign('tiku_question_audit_status')}]];
    const prefix = ctx + "tiku/answer";

    $(function () {
        const options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            sortName: "likeCount",
            sortOrder: "desc",
            modalName: "答案列表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false,
                    sortable: true
                },
                {
                    field: "createBy",
                    title: "发布者"
                },
                {
                    field: 'createTime',
                    title: '发布时间',
                    sortable: true
                },
                {
                    field: "updateBy",
                    title: "最近更新"
                },
                {
                    field: "likeCount",
                    title: "点赞数"
                },
                {
                    field: 'orderNum',
                    title: '显示顺序',
                    visible: false,
                    sortable: true
                },
                {
                    field: 'auditStatus',
                    title: '审核状态',
                    align: 'center',
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(tiku_question_audit_status, item.auditStatus);
                    }
                },
                {
                    field: 'use',
                    title: '使用状态',
                    align: "left",
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(sys_use_status, item.use);
                    }
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    visible: false,
                    sortable: true
                },
                {
                    field: "remark",
                    title: "备注",
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        const actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="answerDetail(\'' + row.id + '\')"><i class="fa fa-chevron-circle-right"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-warning btn-xs ' + '" href="javascript:void(0)" onclick="reAudit(\'' + row.id + '\')"><i class="fa fa-eye"></i>复审</a>');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /*查看答案详情*/
    function answerDetail(id) {
        const url = prefix + '/detail/' + id;
        $.modal.open("答案详情", url);
    }

    /*字典数据-新增字典*/
    function add() {
        const questionId = $("input[name='questionId']").val();
        $.operate.addFull(questionId);
    }

    /*复审*/
    function reAudit(id) {
        $.ajax({
            cache: true,
            type: "POST",
            url: prefix + "/reAudit/" + id,
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }

</script>
</body>
</html>